package com.maker.ai.config;

import dev.langchain4j.mcp.McpToolProvider;
import dev.langchain4j.mcp.client.DefaultMcpClient;
import dev.langchain4j.mcp.client.McpClient;
import dev.langchain4j.mcp.client.transport.McpTransport;
import dev.langchain4j.mcp.client.transport.stdio.StdioMcpTransport;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;

@Configuration
public class McpConfig {
    @Resource
    private OpenAiStreamingChatModel  openAiStreamingChatModel;

    @Value("${mcp.key}")
    private String key;


    @Bean
    public McpClient mcpClient() {
        McpTransport transport = new StdioMcpTransport.Builder()
                .command(List.of("cmd", "/c", "npx","-y","@baidumap/mcp-server-baidu-map"))
                .environment(Map.of("BAIDU_MAP_API_KEY", key))
                .logEvents(true) // only if you want to see the traffic in the log
                .build();
        return new DefaultMcpClient.Builder()
                .transport(transport)
                .build();
    }
    @Bean
    public McpToolProvider toolProvider(McpClient mcpClient){
       return McpToolProvider.builder()
            .mcpClients(mcpClient)
            .build();
    }
//    @Bean
//    public McpChatService mcpChatService(McpToolProvider toolProvider){
//        return AiServices.builder(McpChatService.class)
//                .streamingChatModel(openAiStreamingChatModel)
//                .toolProvider(toolProvider)
//                .build();
//    }
}
